$(document).ready(function () {

	InitBinding();
});



function InitBinding() {

 
	//On submit on add page, submit the add and shows the success
	//page it the edit was successful, otherwise add page is shown again including
	//validation errors
    $("#Submit").click(function (e) {
        e.preventDefault();
        CallPostRequestForOpen();
    });
}



//Ajax request to load in next page of results
function CallPostRequestForOpen() {

    var formData = $("#OpenFromWebForm").serialize();

    $.post("/CodeSnippet/OpenFromWeb", formData, function (response) {
        $("#AjaxContents").replaceWith(response);
	    InitBinding();

	    var successfulParse = $('#successfulParse').val();
	    if (successfulParse == "True") {
	        showOkDialog('Your parsed snippet is shown below', 180, 'Error');

	        SwitchHightlighting($("#HighlightingCSSToUse").val());

	    }
	    else {
	        showOkDialog('Could not parse your code snippet', 180, 'Error');
	    }
	});
	return false;
}
